<script async src="https://www.google-analytics.com/analytics.js"></script>
<script async src="{{ site.baseurl }}/assets/javascripts/autotrack.js"></script>
<script>

window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', '{{ site.google_analytics }}', 'auto');

ga('require', 'cleanUrlTracker', {
  trailingSlash: 'remove'
});
ga('require', 'maxScrollTracker');
ga('require', 'mediaQueryTracker', {
  definitions: [
    {
      name: 'Breakpoint',
      dimensionIndex: 1,
      items: [
        {name: 'sm', media: 'all'},
        {name: 'md', media: '(min-width: 768px)'},
        {name: 'lg', media: '(min-width: 1200px)'}
      ]
    },
    {
      name: 'Pixel Density',
      dimensionIndex: 2,
      items: [
        {name: '1x',   media: 'all'},
        {name: '1.5x', media: '(min-resolution: 144dpi)'},
        {name: '2x',   media: '(min-resolution: 192dpi)'}
      ]
    },
    {
      name: 'Orientation',
      dimensionIndex: 3,
      items: [
        {name: 'landscape', media: '(orientation: landscape)'},
        {name: 'portrait',  media: '(orientation: portrait)'}
      ]
    }
  ]
});
ga('require', 'outboundLinkTracker', {
  events: ['click', 'auxclick', 'contextmenu']
});
ga('require', 'pageVisibilityTracker', {
  sendInitialPageview: true,
});

ga('send', 'pageview');

function sendGaEvent(category, action, element, value) {
    var title = element.getAttribute('title');
    var textConent = element.textContent ? element.textContent.trim() : undefined;
    var label = (title && title.length !== 0) ? title : textConent;
    ga('send', {
        hitType: 'event',
        eventCategory: category,
        eventAction: action.trim(),
        eventLabel: label,
        eventValue: value
    });
}
</script>